import React from 'react'
import T from 'prop-types'
// import { getFullDate } from 'common/utils'
import './index.scss'
import format from '../../../../../utils/format'

// 气泡框前的昵称和时间
export default function MessageHeader(props) {
  const { message = {}, myProfile = {}, groupMemberMap = {} } = props

  // 这里其实可以判断一下，如果是私聊就不显示昵称
  const from = () => {
    // console.log(isMine())
    return message.fromName
    // message.nick ||
    // (groupMemberMap[message.from] && groupMemberMap[message.from].nick) ||
    // message.from
  }

  // 是否是自己发送的消息
  const isMine = () => {
    return (message.fromid || message.userid) === myProfile.userID
  }

  const date = () => {
    return format(message.createTime, 'yyyy-MM-dd HH:mm:ss')
  }

  return (
    <div className={`message-header ${isMine() ? 'right' : 'left'}`}>
      <div className={'name'}>{from()}</div>
      <div>{date()}</div>
    </div>
  )
}

MessageHeader.propTypes = {
  message: T.object,
  myProfile: T.object,
  groupMemberMap: T.object,
}
